<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <erp-car-using-form
      ref="realForm"
      @ok="submitCallback"
      @close="closeCallback"
      @unButtonDisable="unButtonDisable"
      :disabled="disableSubmit"
      normal></erp-car-using-form>
    <div class="drawer-footer">
      <a-popconfirm title="确定关闭弹窗吗?" @confirm="handleCancel" :getPopupContainer="(node) => node.parentNode">
        <a-button style="margin-bottom: 0; z-index: 999;">关闭</a-button>
      </a-popconfirm>
      <a-button v-if="!disableSubmit" type="primary" @click="saveAndSubmit" :disabled="isDisabledAuth('erpCarUsing:startProcess')">发起流程</a-button>
      <!--迭代15 删除了保存功能-->
      <!--      <a-button v-if="!disableSubmit" :disabled="buttonDisable" @click="handleOk" type="primary" style="margin-bottom: 0;  z-index: 999;">保存</a-button>-->
    </div>
  </a-drawer>
</template>

<script>

import ErpCarUsingForm from './ErpCarUsingForm'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'

export default {
  name: 'ErpCarUsingModal',
  mixins: [DisabledAuthFilterMixin],
  components: {
    ErpCarUsingForm
  },
  data () {
    return {
      title: '操作',
      width: 900,
      visible: false,
      disableSubmit: false,
      buttonDisable: false
    }
  },
  methods: {
    add (record) {
      this.buttonDisable = false;
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add(record);
      })
    },
    edit (record) {
      this.buttonDisable = false;
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record);
      });
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    closeCallback () {
      this.close()
    },
    submitCallback () {
      this.$emit('ok');
      this.visible = false;
    },
    handleOk () {
      this.buttonDisable = true;
      this.$refs.realForm.submitForm();
    },
    handleCancel () {
      this.close()
    },
    unButtonDisable () {
      this.buttonDisable = false;
    },
    // 保存成功后发起流程
    async saveAndSubmit() {
      this.$refs.realForm.saveAndSubmit();
    }
  }
}
</script>

<style lang="less" scoped>
/** Button按钮间距 */
.ant-btn {
  margin-left: 30px;
  margin-bottom: 30px;
  float: right;
}
.drawer-footer{
  position: absolute;
  bottom: -8px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
  z-index: 999;
}
</style>
